import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import type { SizeType } from 'antd/lib/config-provider/SizeContext'
import { GlobalState } from '../type'

const globalState: GlobalState = {
  token: '',
  language: 'en',
  assemblySize: 'large',
  theme: {
    colorPrimary: '#824C96',
    isDark: false,
    weakOrGray: ''
  }
}

const globalSlice = createSlice({
  name: 'global',
  initialState: globalState,
  reducers: {
    setToken(state: GlobalState, { payload }: PayloadAction<string>) {
      state.token = payload
    },
    setLanguage(state: GlobalState, { payload }: PayloadAction<string>) {
      state.language = payload
    },
    setAssemblySize(state: GlobalState, { payload }: PayloadAction<SizeType>) {
      state.assemblySize = payload
    },
    setDark(state: GlobalState, { payload }: PayloadAction<boolean>) {
      state.theme.isDark = payload
    },
    setWrakOrGrey(state: GlobalState, { payload }: PayloadAction<string>) {
      state.theme.weakOrGray = payload
    }
  }
})

export const { setToken, setLanguage, setAssemblySize, setDark, setWrakOrGrey } = globalSlice.actions
export default globalSlice.reducer
